# simple gcc/sdl makefile for pceemu

VERSION = "0.0.1"
NAME = pceemu

CC = gcc
CXX = g++
LD = g++

CFLAGS = -DLOGGER -I. -g
#CFLAGS += -DWIN32 -DWIN32GUI
CFLAGS += -DLINUX -DSDL
CXXFLAGS = $(CFLAGS)
LDFLAGS =
LIBS = -lz
#LIBS += -lkernel32 -lshell32 -lshfolder -lgdi32 -ldxguid -lddraw
LIBS += -lSDL -lSDLmain
MAKEDEPEND = g++ -M $(CPPFLAGS) -o $*.d $<

OUTPUT = pceemu

SOURCE = pceemu.c log.c screenshot.c
SOURCE += pce/pce.c pce/rom.c pce/io.c pce/vdc.c pce/vce.c pce/psg.c
SOURCE += pce/state/blocks.c pce/state/state.c
SOURCE += pce/cpu/hu6280.c pce/cpu/hu6280_disasm.c

SOURCE += gui2/gui2.c gui2/elements/menubar.c gui2/elements/menu.c gui2/elements/menuitem.c gui2/elements/button.c gui2/windows/load.c gui2/elements/scrollbar.c
SOURCE += gui2/elements/edit.c gui2/elements/text.c gui2/elements/list.c gui2/elements/radio.c gui2/elements/radiogroup.c gui2/elements/checkbox.c gui2/font_zsnes.c
SOURCE += gui2/windows/videocfg.c gui2/windows/inputcfg.c gui2/windows/soundcfg.c gui2/windows/about.c gui2/gui2_draw.c
SOURCE += gui2/windows/options.c gui2/windows/paths.c gui2/windows/gui_input.c
SOURCE += gui2/windows/tracer.c gui2/windows/rom_info.c gui2/windows/memory_viewer.c

SOURCE += system/config.c

LNXSOURCE += system/linux/filesystem.c system/linux/stricmp.c

SDLSOURCE = system/sdl/video.c system/sdl/input.c system/sdl/sound.c
SDLSOURCE += system/sdl/system.c system/sdl/file.c system/sdl/defaults.c

FLTSOURCE = system/sdl/scale2x/scalebit.c system/sdl/scale2x/scale2x.c system/sdl/scale2x/scale3x.c
FLTSOURCE += system/sdl/hq2x/hq2x.c system/sdl/hq2x/hq3x.c
FLTSOURCE += system/sdl/interpolate/interpolate.c system/sdl/draw/draw.c

W32SOURCE = system/win32/dx7video.c system/win32/defaults.c
W32SOURCE += system/win32/pceemu-res.c system/win32/window.c system/win32/winmain.c 
W32SOURCE += system/win32/video.cpp system/win32/input.c system/win32/sound.c
W32SOURCE += system/win32/file.c system/win32/filesystem.c system/win32/system.c

SOURCE += $(LNXSOURCE) $(SDLSOURCE) $(FLTSOURCE)

CSOURCE = $(filter %.c,$(SOURCE))
CXXSOURCE = $(filter %.cpp,$(SOURCE))

OBJECT = $(sort $(CSOURCE:.c=.o) $(CXXSOURCE:.cpp=.o))

%.P: %.c
	$(MAKEDEPEND)
	@sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' < $*.d > $@; \
		rm -f $*.d; [ -s $@ ] || rm -f $@

#include $(OBJECT:.o=.P)

$(OUTPUT): $(OBJECT)
	$(LD) -o $@ $(LDFLAGS) $(OBJECT) $(LIBS)

all: version.h $(OUTPUT)

clean:
	rm -rf $(OUTPUT) $(OBJECT)

cleancpu:
	rm -rf $(OUTPUT) pce/cpu/hu6280.o pce/cpu/hu6280_disasm.o

version.h:
	rm -rf $@
	echo "#ifndef __version_h__" >> $@
	echo "#define __version_h__" >> $@
	echo "#define VERSION \"$(VERSION)\"" >> $@
	echo "#define APPNAME \"$(NAME)\"" >> $@
	echo "#define APPCLASSNAME \"$(NAME)CLASSNAME\"" >> $@
	echo "#endif" >> version.h

system/win32/pceemu-res.o:
	windres -Isystem/win32 $(@D)/pceemu.rc $@

TESTROM = test.pce
#keith.pce

run: all
	$(OUTPUT) $(TESTROM)
	
gdb: all
	gdb $(OUTPUT) -ex "run cart.pce"

